package com.archerdu.demo.work;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

public class DateTriggerEvent
        implements TriggerEvent {
    
    private static String DATE_FORMATE = "yyyy-MM-dd hh:mm:ss";
    
    @Override
    public boolean trigger(Work condition, Work work) {
        boolean result = false;
        try {
            Date date = DateUtils.parseDate(condition.getTriggerData(), new String[] { DATE_FORMATE });
            if(condition.getPreStartTime().compareTo(date) >= 0){
                result = true;
            }
        }
        catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }
    
    public static void main(String[] args) {
        Work condition = new Work();
        condition.setPreStartTime(new Date());
        
        condition.setTriggerData("2013-12-02 12:00:00");
        
        DateTriggerEvent dte = new DateTriggerEvent();
        
        System.out.println(dte.trigger(condition, null));
        
        condition.setTriggerData("2012-12-02 12:00:00");
        
        System.out.println(dte.trigger(condition, null));

    }
    
}
